﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsThuocTinhHangHoa
    {
        private string mKhoaHangHoa = "";
        private string mKhoaThuocTinh = "";
        private string mNoiDung = "";

        public bool Load(string pKhoaHangHoa, string pKhoaThuocTinh)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM DM_ThuocTinhHangHoa WHERE KhoaHangHoa = '" + pKhoaHangHoa + "' And KhoaThuocTinh = '" + pKhoaThuocTinh + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoaHangHoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaThuocTinh = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mNoiDung = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[3];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaHangHoa", DbType.Int64, ParameterDirection.Input, this.mKhoaHangHoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaThuocTinh", DbType.Int64, ParameterDirection.Input, this.mKhoaThuocTinh);
                commandParameters[2] = DBHelper.createParameter("@NoiDung", DbType.Int64, ParameterDirection.Input, this.mNoiDung);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "sp_DM_ThuocTinhHangHoa", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public DataTable ShowList(string strKhoaHangHoa)
        {
            DataTable table;
            string commandText = "";
            try
            {
                commandText = " SELECT TS.Khoa, TS.Ten" + modGeneral.H_LANGUAGE + " as ThuocTinh,  IsNull(TT.NoiDung,'') as NoiDung  FROM DM_ThuocTinhHangHoa TT right join DM_ThongSoHangHoa TS on TT.KhoaThuocTinh = TS.Khoa and TT.KhoaHangHoa = '" + strKhoaHangHoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string KhoaHangHoa
        {
            get
            {
                return this.mKhoaHangHoa;
            }
            set
            {
                this.mKhoaHangHoa = value;
            }
        }

        public string KhoaThuocTinh
        {
            get
            {
                return this.mKhoaThuocTinh;
            }
            set
            {
                this.mKhoaThuocTinh = value;
            }
        }

        public string NoiDung
        {
            get
            {
                return this.mNoiDung;
            }
            set
            {
                this.mNoiDung = value;
            }
        }
    }
}

